#region File Description
//-----------------------------------------------------------------------------
// MainMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace BeatPong
{
    /// <summary>
    /// The main menu screen is the first thing displayed when the game starts up.
    /// </summary>
    class MainMenuScreen : MenuScreen
    {
        #region Initialization


        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        public MainMenuScreen()
            : base("Main Menu")
        {
            // Create our menu entries.
            MenuEntry playGameMenuEntry = new MenuEntry("Play Game");
            MenuEntry recordMenuEntry = new MenuEntry("Record Beats");
            MenuEntry exitMenuEntry = new MenuEntry("Exit");
            //MenuEntry testMenuEntry = new MenuEntry("test");

            // Hook up menu event handlers.
            playGameMenuEntry.Selected += PlayGameMenuEntrySelected;
            recordMenuEntry.Selected += RecordBeatsEntrySelected;
            exitMenuEntry.Selected += OnCancel;
            //testMenuEntry.Selected += TestMenuEntrySelected;

            // Add entries to the menu.
            MenuEntries.Add(playGameMenuEntry);
            MenuEntries.Add(recordMenuEntry);
            MenuEntries.Add(exitMenuEntry);
            //MenuEntries.Add(testMenuEntry);
        }


        #endregion

        #region Handle Input

        void RecordBeatsEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.AddScreen(new RecorderScreen(), e.PlayerIndex);
        }

        /// <summary>
        /// Event handler for when the Play Game menu entry is selected.
        /// </summary>
        void PlayGameMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.AddScreen(new SongPickerScreen(), e.PlayerIndex);
        }

        /// <summary>
        /// When the user cancels the main menu, ask if they want to exit the sample.
        /// </summary>
        protected override void OnCancel(PlayerIndex playerIndex)
        {
            const string message = "Are you sure you want to exit this sample?";

            MessageBoxScreen confirmExitMessageBox = new MessageBoxScreen(message);

            confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted;

            ScreenManager.AddScreen(confirmExitMessageBox, playerIndex);
        }

        //void TestMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        //{
        //    GameSong song = new GameSong();

        //    XmlSerializer serializer = new XmlSerializer(typeof(GameSong));
        //    StreamReader reader = new StreamReader("Song.xml");
        //    song = (GameSong)serializer.Deserialize(reader);

        //    reader.Close();

        //    song.Artist = "Artist";
        //    song.AssetName = "AssetName";
        //    Beat b = new Beat(new TimeSpan(0, 0, 0, 0, 500));
        //    song.beats = new Beat[] { b, new Beat(new TimeSpan(0, 0, 0, 0, 1000))};
        //    song.length = new System.TimeSpan(0, 5, 0);
        //    song.Title = "Title";
            
            
        //    StreamWriter writer = new StreamWriter("Song.xml");
        //    serializer.Serialize(writer, song);
        //    writer.Close();

        //}

        /// <summary>
        /// Event handler for when the user selects ok on the "are you sure
        /// you want to exit" message box.
        /// </summary>
        void ConfirmExitMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.Game.Exit();
        }


        #endregion
    }
}
